package com.jhhc.Weathers.datasupplement.service.impl;

import com.jhhc.Weathers.datasupplement.dao.BdmsWfProductFDao;
import com.jhhc.Weathers.datasupplement.entity.BdmsWfProductF;
import com.jhhc.Weathers.datasupplement.service.JcdzService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LYQ
 */
@Service("JcdzService")
public class JcdzServiceImpl implements JcdzService {

    @Resource
    private BdmsWfProductFDao fDao;

    @Override
    public int insertBatch(List<BdmsWfProductF> fList) {
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        int batchCount = 200;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < fList.size() -1;) {
            if(batchLastIndex > fList.size() - 1){
                batchLastIndex = fList.size() - 1;
                count = fDao.insertBatch(fList.subList(index,batchLastIndex + 1));
                num+=count;
                break;
            }else {
                count = fDao.insertBatch(fList.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);
            }
            num+=count;
        }
        return num;
    }

    @Override
    public int select(String provideid, String gridnm, String rtm) {
        return fDao.select(provideid, gridnm, rtm);
    }

    @Override
    public int selectSG(String provideid, String gridnm, String rtm) {
        return fDao.selectSG(provideid, gridnm, rtm);
    }

    @Override
    public int delete(String provideid, String gridnm, String rtm) {
        return fDao.delete(provideid, gridnm, rtm);
    }
}
